/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logica.cliente;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.cliente.*;

/**
 *
 * @author davi
 */
public class ExcluiCliente implements logica.Logica {

    @Override
    public void executa(HttpServletRequest req, HttpServletResponse res) throws Exception {
        
        String id = req.getParameter("id");
        id = id.trim();
        
        Cliente c = new ClienteDAO().buscaClienteDetalhes(id);
        
         try{
        ClienteDAO dao = new ClienteDAO();
        dao.excluir(c);
        }
        catch(Exception e ){
        
        e.printStackTrace();
        RequestDispatcher rd = req.getRequestDispatcher("erro.jsp");
        rd.forward(req, res);
        }
        
        req.setAttribute("cliente", c);
        req.setAttribute("operacao", "excluir");
        RequestDispatcher rd = req.getRequestDispatcher("sucesso.jsp");
        rd.forward(req, res);
        
    }
    
}
